<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="chtml" uri="http://www.szhelper.com/jsp/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>系统监控</title>
<script>
	var WindowObjectReference = null; // global variable
	var autoScroll = true;
	var stopMonitor = true;

	function openFFPromotionPopup(url) {
		if (WindowObjectReference == null || WindowObjectReference.closed) {
			WindowObjectReference = window
					.open(url, "PromoteFirefoxWindowName");
		} else {
			WindowObjectReference.focus();
		}
		;
	}

	function viewDetail() {
		var messageid = document.getElementById('messageId').value;
		var a = Math.random();
		$
				.getJSON(
						"../systemmonitor/" + messageid + "?rand=" + a,
						function(monitor) {
							openFFPromotionPopup("about:blank");
							if(WindowObjectReference != null)
							{
								WindowObjectReference.document.clear();
								WindowObjectReference.document.location.href = messageid;
								WindowObjectReference.document.title = messageid;
								WindowObjectReference.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
								WindowObjectReference.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"zh-CN\" lang=\"zh-CN\">");
								WindowObjectReference.document.write("<head><title>详细信息</title></head><body>");
								WindowObjectReference.document.write(monitor)
								WindowObjectReference.document.write("</body></html>")
								WindowObjectReference.document.close();
							}
							else
							{
								alert("WindowObjectReference is null");
							}
							}
						);
	}

	function refreshProgress() {
		var a = Math.random();
		$
				.getJSON(
						"../systemmonitor/list?rand=" + a,
						function(monitor) {
							if (monitor == null) {
								window.setTimeout('refreshProgress()', 1000);
							} else {
								document.getElementById('divUploadStatus').innerHTML += monitor;
								if (autoScroll) {
									document.getElementById("divUploadStatus").scrollTop += 99999999;
								}
								if (!stopMonitor) {
									window
											.setTimeout('refreshProgress()',
													1000);
									var submit = document
											.getElementById('customButton');
									submit.disabled = true;
								} else {
									var submit = document
											.getElementById('customButton');
									submit.disabled = false;
								}
							}
						});
	}

	function startProgress() {
		if (stopMonitor) {
			stopMonitor = false;
		}
		refreshProgress();
	}

	function stopProgress() {
		stopMonitor = true;
	}

	function clearMonitor() {
		document.getElementById('divUploadStatus').innerHTML = "";
	}

	function switchAutoScroll() {
		if (autoScroll) {
			autoScroll = false;
			document.getElementById('scrollButton').value = "窗口自动滚动";
		} else {
			autoScroll = true;
			document.getElementById('scrollButton').value = "窗口停止滚动";
		}
	}

	refreshProgress();
</script>
</head>
<body style="margin: 0; padding: 0; background: #ffffff;">
	<form method="post">
		<table width="80%" border="0" cellspacing="2" cellpadding="0"
			align="center">
			<tr>
				<td align="center" height="30"><input id="customButton"
					name="customButton" type="button" class="Button" value="开始性能测试"
					onclick="startProgress()" />&nbsp;<input id="clearButton"
					name="clearButton" type="button" class="Button" value="清空监控日志"
					onclick="clearMonitor()" />&nbsp;<input id="scrollButton"
					name="scrollButton" type="button" class="Button" value="窗口停止滚动"
					onclick="switchAutoScroll()" />&nbsp;&nbsp;&nbsp; 输入消息编号：<input id="messageId" name="messageId" type="text" size="6"
					/>&nbsp;<input id="customButton" name="customButton"
					type="button" class="Button" value="查看事件详细信息"
					onclick="viewDetail()" /></td>
			</tr>
			<tr>
				<td>
					<div
						style="height: 380px; line-height: 20px; overflow: scroll; overflow-x: hidden; border-style: solid; border-width: 1px; border-color: #000000"
						id="divUploadStatus"></div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
